<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>

	<head>
		<jsp:include page="../inc.jsp"></jsp:include>
		<jsp:include page="../inc_bootstrap.jsp"></jsp:include>
		<link rel="stylesheet" href="${ctx }/css/settlementQuery.css"/>
		<link rel="stylesheet" href="${ctx}/css/iconfont.css"/>
		<meta http-equiv="X-UA-Compatible" content="edge" />
		<c:if test="${fn:contains(sessionInfo.resourceList, '/user/edit')}">
			<script type="text/javascript">
				$.canEdit = true;
			</script>
		</c:if>
		<c:if test="${fn:contains(sessionInfo.resourceList, '/user/delete')}">
			<script type="text/javascript">
				$.canDelete = true;
			</script>
		</c:if>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>用户管理</title>
		<style type="text/css">
			.mynewBtn{
				text-align: center;
			}
		</style>
		<script type="text/javascript">
			$(function() {
				//状态背景文字切换
				$(".listArg").click(function(){
					changeBack($(".listArg"),$(this));

				});
				//加载列表信息
				$('#table').bootstrapTable({
					url: '${ctx}/user/operatorGrid?temp='+Math.random(),
					dataType: "json",
					//contentType: "application/x-www-form-urlencoded",
					method: 'get',
					cache: false,
					height: "auto",//
					pagination: true,
					pageSize: 20,
					pageNumber:1,
					pageList: [ 20, 50, 100, 200, 500],
					striped: false,
					search: false,
					showColumns: false,
					showRefresh: false,
					clickToSelect: true,
					idField:'id',
					toolbar: "#toolbar",
					paginationHAlign: 'left',
					paginationDetailHAlign: 'right',
					sidePagination: "server", //表示服务端请求
					queryParamsType : "undefined",
					//queryParams: queryParams,//参数
					columns: [
						{field:"id",title:"",align:"left",valign:"middle",visible:false},
						{field:"loginname",title:"登录名",align:"center",valign:"middle"},
						{field:"name",title:"姓名",align:"center",valign:"middle"},
						{field:"organizationId",title:"部门ID",align:"center",valign:"middle"},
						{field:"organizationName",title:"所属部门",align:"center",valign:"middle"},
						{field:"createdatetime",title:"创建时间",align:"center",valign:"middle"},
						{field:"sex",title:"性别",align:"center",valign:"middle",
							formatter: function(value, row, index) {
								switch(value) {
									case 0:
										return '男';
									case 1:
										return '女';
								}
							}
						},
						{field:"age",title:"年龄",align:"center",valign:"middle"},
						{field:"isdefault",title:"是否默认",align:"center",valign:"middle",
							formatter: function(value, row, index) {
								switch(value) {
									case 0:
										return '默认';
									case 1:
										return '否';
								}
							}
						},
						{field:"state",title:"状态",align:"center",valign:"middle",
							formatter: function(value, row, index) {
								switch(value) {
									case 0:
										return '正常';
									case 1:
										return '停用';
								}
							}
						},
						{field:"mobile",title:"电话",align:"center",valign:"middle"},
						{field:"email",title:"邮箱",align:"center",valign:"middle"},
						{field: 'act', title: '操作', align:"center",valign:"middle",
							formatter: function(value, row, index) {
								var str='';
								if($.canEdit){
									//str += '<span class="mynewBtn" onclick=editFun("'+row.id+'"); >编辑</span>';
									str +='<i class="icon iconfont position" title="编辑" onclick=editFun("'+row.id+'")>&#xe601;</i>';
								}
								if($.canDelete){
									//str += '<span class="mynewBtn" onclick=resetPwd("'+row.id+'"); >重置密码</span>';
									str +='<i class="icon iconfont position" title="重置密码" onclick=resetPwd("'+row.id+'");>&#xe64c;</i>';
								}
								return str;
							}
						}
					],
					formatNoMatches: function(){
						return '无符合条件的记录';
					}
				});

			});

			function addFun() {
				
				layer.open({
					type: 2,
					title: '添加营业员',
					shadeClose: true,
					shade: 0.3,
					closeBtn: 1, //不显示关闭按钮
					yes: function(index, layero) {
						layer.close(index);
					},
					area: ['700px', '450px'],
					content: ['${ctx}/user/toOperatorAdd', 'no'], //iframe的url，no代表不显示滚动条
					end:function(){
						 $('#dataGrid').datagrid('load',{url:'${ctx}/user/dataGrid?temp='+Math.random(),organizationId: '${sessionScope.sessionInfo.orgId}',usertype:2});
					}
				});
			}
			//重置密码
			function resetPwd(id) {
				layer.alert('确认要重置密码吗？',{skin:'layui-layer-lan',title: ['系统提示', 'background-color:#00B2EE; color:#fff;'],closeBtn: 1}, function(index){
					layer.close(index);
					progressLoad();
					$.post('${ctx}/user/resetPwd', {
						id: id,
						password:'888888'
					}, function(result) {
						if(result.success) {
							layer.alert("密码重置成功，默认密码888888",{skin:'layui-layer-lan',title: ['系统提示', 'background-color:#00B2EE; color:#fff;'],closeBtn: 0}, function(index){
							    layer.closeAll();
							});
						}else{
							layer.alert("密码重置失败！",{skin:'layui-layer-lan',title: ['系统提示', 'background-color:#00B2EE; color:#fff;'],closeBtn: 0}, function(index){
							    layer.closeAll();
							});
						}
						progressClose();
					}, 'JSON');
				}); 
			};
			
			function editFun(id) {
				layer.open({
					type: 2,
					title: ['编辑营业员','background-color:#00B2EE; color:#fff;'],
					shadeClose: true,
					shade: 0.3,
					closeBtn: 1, //不显示关闭按钮
					yes: function(index, layero) {
						layer.close(index);
					},
					area: ['1100px', '450px'],
					content: ['${ctx}/user/toOperatorEdit?id='+id, 'no'], //iframe的url，no代表不显示滚动条
					end:function(){
						 $('#dataGrid').datagrid('load',{url:'${ctx}/user/dataGrid?temp='+Math.random(),organizationId: '${sessionScope.sessionInfo.orgId}',usertype:2});
					}
				}); 
			}

			//封装函数  实现背景颜色及字体颜色切换
			function changeBack(arg,$this){
				arg.css({
					"background": "#f1f1f1",
					"color": "black"
				});
				$this.css({
					"background": "#34c0e3",
					"color": "#FFFFFF"
				});
			};
		</script>
	</head>

	<body>
	<jsp:include page="../head.jsp"></jsp:include>
		<div class="setTabBox">
			<table id="table"></table>
		</div>
		<div id="toolbar">
			<c:if test="${fn:contains(sessionInfo.resourceList, '/user/add')}">
				<%--<a onclick="addFun();" href="javascript:void(0);">添加</a>--%>
				<input type="button" class="query" value="&nbsp;&nbsp;添加&nbsp;&nbsp;" onclick='addFun()'/>
			</c:if>
		</div>
	<jsp:include page="../footer.jsp"/>
	</body>

</html>